package com.thread;

import java.util.concurrent.atomic.AtomicInteger;

public class Main {
    static AtomicInteger  integer = new AtomicInteger();
    static volatile boolean flag = false;
    public static void main(String[] args) {


        new Thread(()->{
            while (integer.get()<=200){
                if (flag) {

                    System.out.println("Thread 1: " + integer.getAndIncrement());
                    flag=false;                }
            }
        }).start();

        new Thread(()->{
            while (integer.get()<=200){
                if (!flag) {
                    System.out.println("Thread 2: "+integer.getAndIncrement());
                    flag=true;
                }

            }
        }).start();
    }
}